import React, { Component } from 'react';
import { Button, Input } from 'antd';
import { autorun } from 'mobx';
import { observer } from 'mobx-react';

@observer(['app'])
class Login extends Component {

  componentDidMount() {
    autorun(this.handleLoggedIn);
  }

  /**
   * 登陆后的处理
   */
  handleLoggedIn = () => {

    const { app, history } = this.props;
    if (app.me) {
      history.replace('/');
    }
  }

  render() {

    return (
      <div style={{marginTop: 120}}>
        <Button type='ghost' onClick={this.handleLogin}>Login</Button>
      </div>
    )
  }

  handleLogin = () => {
    const { app } = this.props;
    app.login();
  }
};

export default Login;